package com.marklogic.ps.servicetester;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.marklogic.ps.servicetester.gui.QueryPanel;
import com.marklogic.ps.servicetester.services.ServiceHelper;
import com.marklogic.ps.servicetester.services.ServicesServiceImpl;

/**
 * @author mhelmstetter
 * @version $Revision: 1.3 $
 * 
 */
public class ServiceTesterApplet extends JApplet {

    @Override
	public void setSize(int width, int height) {
    	System.out.println("setSize(): width: " + width + " height: " + height);
		//super.setSize(width, height);
		resize(width, height);
		validate();
	}
    
    public void pack() {
        Container cp = getContentPane();
        Dimension d = cp.getLayout().preferredLayoutSize(cp);
        setSize((int)d.getWidth(),(int)d.getHeight());
      }
	
    private void buildGui() {
        //setSize(800, 600);

    	try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// QueryController controller = new QueryControllerImpl();
		String baseUrl = "http://localhost:9001/";
		ServiceHelper serviceHelper = new ServiceHelper(null);
		ServicesServiceImpl s = new ServicesServiceImpl();
		QueryPanel qp = new QueryPanel();
		qp.setServicesService(s);
		qp.init(null);
    	qp.setSize(800, 600);
    	
        //qp.setPreferredSize(new Dimension(800, 600));
        //this.getContentPane().add(qp, BorderLayout.CENTER);
        //getContentPane().add(qp);
		this.getContentPane().setLayout(new GridLayout());
        this.getContentPane().add(qp);
        pack();
    }

    public void init() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                public void run() {
                    buildGui();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
